<?php

namespace App\Services\CloseUnpaidProductOrder;

use App\Http\Controllers\Api\V1\Requests\FormRequest;
use Illuminate\Support\Facades\Redis;

class CloseUnpaidProductOrderRequest extends FormRequest
{
	public function rules()
	{
		return [
			'cache_id' => [
				'required','string', $this->verify()
			]
		];
	}
	
	public function verify()
	{

		return function ($attribute, $value, $fail) {

			if (! Redis::exists($value)) {
				return $fail("目标订单不存在:{$value}");
			} elseif (Redis::hGet($value, 'is_paying')) {
				return $fail("目标订单已申请付款:{$value}");
			} elseif (Redis::hGet($value, 'is_paid')) {
				return $fail("目标订单已付款:{$value}");
			} elseif (Redis::hGet($value, 'closed_at')) {
				return $fail("目标订单已关闭:{$value}");
			}
			return true;
		};
	}
}
